package pooller.model.adapters;

import pooller.dto.pool.SurviveVariantDto;
import pooller.model.pool.SurvivorVariants;

import java.util.stream.Collectors;

public interface SurviveVariantAdapter extends DtoAdapter<SurvivorVariants, SurviveVariantDto> {
    SurviveVariantAdapter I = new SurviveVariantAdapter() {};
    @Override
    default SurvivorVariants fromDto(SurviveVariantDto dto) {
        return DtoAdapter.super.fromDto(dto);
    }

    @Override
    default SurviveVariantDto toDto(SurvivorVariants entity) {
        if (entity == null) {
            return null;
        }
        SurviveVariantDto dto = new SurviveVariantDto();
        dto.setQuestionDto(PoolQuestionAdapter.I.toDto(entity.getPoolQuestion()));
        dto.setVariantDto(entity.getQuestionVariants().stream().map(QuestionVariantAdapter.I::toDto).collect(Collectors.toList()));
        return dto;
    }
}
